package exam.wangyi.autumn.S2;

import java.util.*;

public class Main {
    public static int n;
    public static int[] nums;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        nums = new int[n];
        for (int i=0; i<n; ++i)
            nums[i] = sc.nextInt();
        System.out.println(solution());
    }

    private static int solution() {
        int maxNum = 0, maxNumIndex = 0;
        for (int i=0; i<n; ++i) {
            if (nums[i] >= maxNum) {
                maxNum = nums[i];
                maxNumIndex = i;
            }
        }
        boolean flag = false;
        for (int i=0; i<n; ++i) {
            if (i % 2 != maxNumIndex % 2 && nums[i] == maxNum) {
                flag = true;
                break;
            }
        }
        if (flag) {
            int res = 0;
            for (int i = 0; i < n; ++i)
                res += (maxNum - nums[i]);
            return res + n / 2;
        }
        int secondNum = 0;
        for (int i=0; i<n; ++i) {
            if (i % 2 != maxNumIndex % 2) {
                secondNum = Math.max(secondNum, nums[i]);
            }
        }
        int res = 0;
        for (int i=0; i<n; ++i) {
            if (i % 2 == maxNumIndex % 2)
                res += (maxNum - nums[i]);
            else
                res += (secondNum - nums[i]);
        }
        return res;
    }
}